/**
 * 
 */

window.onload = function(){
	
	findInfos();
	//表名
	var tableName = "bill";
	var sendDirection="";
	
//账单查询功能
	var find = document.getElementById("find");
		function findInfos(){
			var tableHead="<table>" +
			"<caption>账单信息表</caption>" +
				"<tr>" +
					"<th>选项</th>" +	
					"<th>账单号</th>" +
					"<th>用户ID</th>" +
					"<th>商品号</th>" +
					"<th>装置号</th>" +
					"<th>付款时间</th>" +
					"<th>使用次数</th>" +
					"<th>支付状态</th>" +
					"<th>优惠券名</th>" +
					"<th>使用优惠券数量</th>" +
					"<th>操作</th>" +
					"</tr>";
			
			var tableBody="";
			var tableTail="</table>";
			
			var xhr = new XMLHttpRequest();
			xhr.onreadystatechange = function(){
				if(xhr.readyState==4){
					if(xhr.status>=200 && xhr.status<300 || xhr.status==304){
						var findResult = xhr.responseText;
					//	console.log("findResult:"+findResult);
						
						if(findResult!="0"){
							var billArray = JSON.parse(findResult);
							for(var i=0;i<billArray.length;i++){
								if(i%2==0){
									tableBody+="<tr id='lightColor'>" +
												"<td><input type='checkbox' value='"+billArray[i].bId+"'/></td>" +
												"<td>"+billArray[i].bId+"</td>" +
												"<td>"+billArray[i].uId+"</td>" +
												"<td>"+billArray[i].gId+"</td>" +
												"<td>"+billArray[i].dId+"</td>" +
												"<td>"+billArray[i].paidTime+"</td>" +
												"<td>"+billArray[i].useTime+"</td>" +
												"<td>"+billArray[i].bStatus+"</td>" +
												"<td>"+billArray[i].cName+"</td>" +
												"<td>"+billArray[i].uCoupon+"</td>" +
												"<td>无</td>" +
											"</tr>";
								}else{
									tableBody+="<tr >" +
											"<td><input type='checkbox' value='"+billArray[i].bId+"'/></td>" +
											"<td>"+billArray[i].bId+"</td>" +
											"<td>"+billArray[i].uId+"</td>" +
											"<td>"+billArray[i].gId+"</td>" +
											"<td>"+billArray[i].dId+"</td>" +
											"<td>"+billArray[i].paidTime+"</td>" +
											"<td>"+billArray[i].useTime+"</td>" +
											"<td>"+billArray[i].bStatus+"</td>" +
											"<td>"+billArray[i].cName+"</td>" +
											"<td>"+billArray[i].uCoupon+"</td>" +
											"<td>无</td>" +
										"</tr>";
								}
							}
							find.innerHTML = tableHead+tableBody+tableTail;
						}else{
							find.innerHTML = "<p>表信息空空如也--''</p>";
						}
						
					}	
				}
			}
			
			xhr.open("post","../bill_FindServlet",true);
			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
			xhr.send("find=allInfo");
			
		}
		
		
//账单删除功能

		
		
}
	



	
